const Koa = require('koa');
const fs = require('fs');
const compress = require('koa-compress');
const app = new Koa();


const url = "http://localhost";
const port = 1314; 

app.use(async (ctx,next) => {
    
    ctx.type = 'html'
    ctx.body = await fs.readFileSync('./index.html');
    ctx.status = 200;
    next();
})

app.use(compress({
    filter:function(content_type) { // 过滤函数，只有返回 true 才执行压缩
        
        return /text/i.test(content_type);
    },
    threshold:1024, // 指定文件大于 1024 才压缩
    flush:require('zlib').Z_SYNC_FLUSH, // 指定压缩算法
}))


app.listen(port,() => {
    console.log(`服务在 ${url}:${port} 上启动来了`);
})